package 药品;

import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.RecordWriter;
import org.apache.hadoop.mapreduce.TaskAttemptContext;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class MyRecordWriter extends RecordWriter<JavaBean, NullWritable> {
    BufferedWriter bw;

    public void write(JavaBean key, NullWritable value) throws IOException, InterruptedException {
        //获取所属管理局
        String glj = key.getQfManagerName();
        String path = "/MR/yaoping/output1"+glj+".txt";
        File file = new File(path);
        bw = new BufferedWriter(new FileWriter(file,true));
        bw.write(key.toString());
        bw.write("\n");
        bw.flush();
    }

    public void close(TaskAttemptContext context) throws IOException, InterruptedException {
        bw.close();
    }
}
